//
//  MSProjectRadarTableVC.m
//  SocietySale
//
//  Created by Mike on 16/11/18.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSProjectRadarTableVC.h"
#import "MSProjectRadarCell.h"

@interface MSProjectRadarTableVC ()
//section头部标题
@property(nonatomic,copy)NSArray *sectionTitleArray;

@end

@implementation MSProjectRadarTableVC

- (void)viewDidLoad{
    [super viewDidLoad];
    self.sectionTitleArray = @[@"客户动态提醒",@"关注及跟踪的项目更新提醒"];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (self.dataArray.count) {
        return [self.dataArray[section] count];
    }
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellId = @"cellId";
    MSProjectRadarCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    if (!cell) {
        cell = [[MSProjectRadarCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    if (indexPath.row == [self.dataArray[indexPath.section] count]-1) {
        cell.horizonLineView.hidden = YES;
    }
    else{
        cell.horizonLineView.hidden = NO;
    }
//    if ([self.dataArray[indexPath.section] count]) {
        cell.valueStr = self.dataArray[indexPath.section][indexPath.row];
//    }
    return cell;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 50;
//}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
    bgView.backgroundColor = [UIColor whiteColor];
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 49.4, SCREEN_WIDTH, 0.6)];
    horizonLineView.backgroundColor = kNormalGray;
    [bgView addSubview:horizonLineView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 200, 50)];
    label.font = HeitiFont(15);
    label.textColor = kLightBlackColor;
    label.text = self.sectionTitleArray[section];
    [bgView addSubview:label];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.tag = section + 10;
    btn.frame = CGRectMake(SCREEN_WIDTH -50, 0, 50, 50);
    [btn setImage:[UIImage imageNamed:@"jia"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(headBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn];
    
    return bgView;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10.0f;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREENFRAME.size.width, 20)];
    bgView.backgroundColor = kDefaultViewBackgroundColor;
    
    UIView *horizonLineView =[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.6)];
    horizonLineView.backgroundColor = kNormalGray;
    [bgView addSubview:horizonLineView];
    return bgView;
}

- (void)headBtnClick:(UIButton*)btn{
    if ([self.delegate respondsToSelector:@selector(clickAddSectionIndex:)]) {
        [((id<MSProjectRadarTableVCDelegate>)self.delegate) clickAddSectionIndex:btn.tag];
    }
}

@end
